using System;
using System.Collections.Generic;
using System.Text;
using DataTools;
using DataTools.PagingUtils;
using ObjectLayer;

namespace CommonAccessLayer
{
	public class branchDAO
{
		public static List<branchBO> GetAll()
		{
			return CBO.FillCollection<branchBO>(DataProvider.getInstance().getAll(TableName.branch, PagingHelper.CreateOrder(new OrderObject(branchTable.code, SortOrder.Desc))));
		}
		static object _Clock = new object();
		public static List<branchBO> GetAllC()
		{
			List<branchBO> list = new List<branchBO>();
			if(DataCache.GetCache(CacheName.branch) == null)
			{
				lock (_Clock)
				{
					if (DataCache.GetCache(CacheName.branch) != null)
					{
						list = (List<branchBO>)DataCache.GetCache(CacheName.branch);
					}
					else
					{
			list = CBO.FillCollection<branchBO>(DataProvider.getInstance().getAll(TableName.branch, PagingHelper.CreateOrder(new OrderObject(branchTable.code, SortOrder.Desc))));
						DataCache.SetCache(CacheName.branch, list);
					}
				}
			}
			else
			{
					list = (List<branchBO>)DataCache.GetCache(CacheName.branch);
			}
		return list;
		}
		public static int InsertUpdateDelete(branchBO branch, ProviderAction action)
		{
			int rs = DataProvider.getInstance().InsertUpdateDelete(action, StoreProcedureName.InsertUpdateDelete_branch, "@" + branchTable.code, branch.code,branch.name, DataTools.ConvertType.ToInt(action));
			if (rs != -1)
			{
				DataCache.RemoveCache(CacheName.branch);
			}
			return rs;
		}
		
	}
}